#include "PolygonCreateAction.h"

using namespace cmn;
using namespace editor_core;

PolygonCreateAction::PolygonCreateAction( const Transform& position, IProvider<BodyEntity*>* parentBodyProvider ) :
	m_position( position ),
	m_parentBodyProvider( parentBodyProvider ),
	m_polygonEntity( 0 )
{}

PolygonCreateAction::~PolygonCreateAction() {}

bool PolygonCreateAction::Commit() {
	BodyEntity* parentBody = m_parentBodyProvider->GetEntity();

	m_polygonEntity = new PolygonEntity( parentBody, m_position );
	parentBody->AddPolygon( m_polygonEntity );
	return true;
}

void PolygonCreateAction::Rollback() {
	BodyEntity* parentBody = m_parentBodyProvider->GetEntity();

	parentBody->RemovePolygon( m_polygonEntity );
	delete m_polygonEntity;
	m_polygonEntity = 0;
}

void PolygonCreateAction::Recommit() {
	Commit();
}

